﻿using B.S.Material.ErrorCode;
using B.S.Material.Wirth.Api.Applications.Command.FeedDetailsCommand;
using B.S.Material.Wirth.Api.Applications.Command.FeedingCommand;
using B.S.Material.Wirth.Api.Applications.Command.MaterialsChildCommand;
using B.S.Material.Wirth.Api.Applications.Command.MaterialsCommnad;
using B.S.Material.Wirth.Api.Applications.Command.MaterialsPickingCommand;
using B.S.Material.Wirth.Api.Applications.Command.MaterialsPickingDetailCommand;
using B.S.Material.Wirth.Api.Dto;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.Material.Wirth.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MentController : ControllerBase
    {
        private readonly IMediator mediator;
        public MentController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 上传附件
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> UpLoadImages(IFormFile file)
        {
            //上传后的文件名称路径
            var res = Directory.GetCurrentDirectory()+@"\wwwroot\Pic\" + file.FileName;
            //上传
            using (FileStream fs = new FileStream(res, FileMode.Create))
            {
                file.CopyTo(fs);
                fs.Flush();
            }
            //输出文件路径+文件名
            return Ok("https://localhost:7077/Pic/" + file.FileName);
        }

        /// <summary>
        /// 物料管理主表添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<object>> AddMaterials(AddMaterialsCommand request)
        {
            return await mediator.Send(request);
        }
      
        /// <summary>
        /// 物料管理主表修改
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> UpdateMaterials([FromBody]UpdateMaterialsCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 物料管理主表删除
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<ApiResult<int>> DelMaterials([FromQuery] DelMaterialsCommand requestn)
        {
            return await mediator.Send(requestn);
        }
        [HttpDelete]
        public async Task<ApiResult<int>> PLDelMaterials([FromQuery] PLDeleMaterialsCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 物料管理子表添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<object>> AddMaterialsChild(AddMaterialsChildCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 批量添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<object>> PLAddMaterials(CreaAddMaterialsChildCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        ///  物料管理子表修改
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> UpdateMaterialsChild(UpdateMaterialsChildCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 物料管理子表删除
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<ApiResult<int>> DelMaterialsChild([FromQuery]DelMaterialsChildCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 生产领料管理添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<object>> AddMaterialsPicking(AddMaterialsPickingCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 生产领料管理修改
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> UpdateMaterialsPicking(UpdateMaterialsPickingCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        ///  生产领料管理删除
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<ApiResult<int>> DelMaterialsPicking([FromQuery] DelMaterialsPickingCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 生产领料明细表添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddMaterialsPickingDetail(AddMaterialsPickingDetailCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 批量添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<object>> CreaPLMaterialsPickingDet(CreaPLMaterialsPickingDetailCommand request)
        {
            return await mediator.Send(request);

        }
        /// <summary>
        /// 生产领料明细表修改
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> UpdateMaterialsPickingDetail(UpdateMaterialsPickingDetailCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 生产领料明细表删除
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<ApiResult<int>> DelMaterialsPickingDetail([FromQuery] DelMaterialsPickingDetailCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 生产补料添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<Object>> AddFeeding(AddFeedingCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 生产补料删除
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<ApiResult<int>> DelFeeding([FromQuery] DelFeedingCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 生产补料修改
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> UpdateFeeding(UpdateFeedingCommand request, CancellationToken cancellationToken)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 生产补料明细表 添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<object>> AddFeedDetails(AddFeedDetailsCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 生产补料明细表 删除
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<ApiResult<int>> DelFeedDetails([FromQuery] DelFeedDetailsCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 生产补料明细表 修改
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> UpdateFeedDetails(UpdateFeedDetailsCommand request)
        {
            
            return await mediator.Send(request);
        }





    }
}
